//导入重置样式
require("../../assets/css/reset.css");
//导入公共样式
require("../../assets/css/basic.css");
//导入标准样式
require("../../assets/css/normalize.css");
//导入iconfont.css
require("../../assets/fonts/iconfont.css");
//导入样式
require("./sports_course_detail.less");
//引入js模块
const dom = require("../../utils/dom.js");
//引入axios公共工具
const axios = require("../../utils/axios.js");

document.addEventListener("DOMContentLoaded", function () {
	//点击返回按钮回到上一个页面
	dom.get(".zp-left").addEventListener("click", function () {
		history.back();
	});
	//获取地址栏传递的参数id
	let id = this.location.search.split("=").pop();
	axios.get("/api/train/courseDetail?id=" + id).then((res) => {
		console.log(res);
		//将视频数据存储到localstorage中
		let data = res.data.data.fragments;
		localStorage.setItem("fragments", JSON.stringify(data));
		let fragments = JSON.parse(localStorage.getItem("fragments"));
		console.log(fragments[0].imgUrl);
		//获取课程,并渲染到页面
		dom.get("#dk").textContent = res.data.data.name;
		dom.get("#desc").textContent = res.data.data.desc;
		dom.get(".carll").textContent = res.data.data.calorie;
		dom.get("#img").src = axios.defaults.baseURL + fragments[0].imgUrl;
	});

	//点击开始训练按钮跳转
	dom.get("#btn").addEventListener("click", function () {
		location.href = "sports_course_play.html";
	});
});
